package reflection.utils;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA
 * Description:获取类结构的API演示2
 * User:22954
 * Date:2024-04-15
 * Time:13:16
 */
public class API2 {
    /*
    getModifier() 返回int : 默认(default)-0  public-1  private-2  protected-4  static-8  final-16
    多个修饰符采用叠加算法
     */
    public static void main(String[] args) throws ClassNotFoundException {
        Class<?> cls = Class.forName("reflection.utils.B");

        Field[] fields = cls.getDeclaredFields();
        for (Field field : fields) {
            System.out.println("修饰符值:" + field.getModifiers() + "  属性类型:" + field.getType());
        }

        Method[] methods = cls.getDeclaredMethods();
        for (Method method : methods) {
            System.out.print("修饰符值:" + method.getModifiers() + "  返回类型:" + method.getReturnType());
            Class<?>[] parameterTypes = method.getParameterTypes();
            for (Class<?> parameterType : parameterTypes) {
                System.out.print("  参数类型:" + parameterType.getName());
            }
            System.out.println();
        }

        Constructor<?>[] declaredConstructors = cls.getDeclaredConstructors();
        for (Constructor<?> constructor : declaredConstructors) {
            Class<?>[] parameterTypes = constructor.getParameterTypes();
            for (Class<?> parameterType : parameterTypes) {
                System.out.println("构造器形参类型:" + parameterType);
            }
        }


    }
}
